<?php


namespace app\admin\order\controller;

use app\admin\order\logic\RechargeOrderLogic;
use app\common\controller\BaseAdminController;
use app\model\order\RechargeOrder;
use support\utils\Time;

/**
 * 用户充值订单
 * Class RechargeOrderController
 * @package app\admin\order\controller
 */
class RechargeOrderController extends BaseAdminController
{
    protected function init()
    {
        parent::init();
        $this->logic = new RechargeOrderLogic();
    }

    public function list()
    {
        $where = [];
        $this->form['user_id'] && $where[] = ['user_id', '=', $this->form['user_id']];
        $this->form['status'] && $where[] = ['status', '=', $this->form['status']];
        $this->form['pay_way'] && $where[] = ['pay_way', '=', $this->form['pay_way']];
        $this->form['recharge_no'] && $where[] = ['recharge_no', 'like', "%{$this->form['recharge_no']}%"];
        $this->form['start_time'] && $this->form['end_time'] && $where[] = ['create_time', "between", [
            Time::getDayStartDateTime($this->form['start_time']),
            Time::getDayEndDateTime($this->form['end_time']),
        ]];
        $query = $this->logic->search($where);
        $query->order("id desc");
        $data = $this->logic->getPageList($query);
        return $this->success($data);
    }

    public function getStatusMap()
    {
        return $this->success([
            "status" => wrapperStatus(RechargeOrder::STATUS_TEXT_MAP),
            "pay_way" => wrapperStatus(RechargeOrder::PAY_WAY_TEXT_MAP),
        ]);
    }


}